<template>
	<view>
		<view class="equipment">
			<!-- 设备列表 -->
			<view class="list" v-for="(de,index) in device" :key="index" @click="details(de)">
				<view class="list_text"><text>{{de.name}}</text></view>
				<view class="list_text2" v-if="de.cloudOnline==true"><text>在线</text></view>
				<view class="list_text2" v-if="de.cloudOnline==false"><text>离线</text></view>
				<view class="cus-mian-four"><text>></text></view>
			</view>

			<view class="tianjia" @click="tianjia">
				<view>
					<image src="../../../static/image/jiahao.png"></image>
				</view>
				<view>
					<text>添加子设备</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				devId: "",
				device: [],
				name: "",
				homeId: "",
			}
		},
		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			this.devId = option.devId;
			// console.log(option.devId)
			this.name = option.name;
			this.homeId = option.homeId
		},
		onShow() {
			this.zishebei();
			this.title();
		},
		methods: {
			title() {
				uni.setNavigationBarTitle({
					title: this.name + "子设备列表"
				});
			},
			tianjia() {
				try {
					uni.showLoading({
						title: '添加子设备中....'
					});
					const DeviceConfigModule = uni.requireNativePlugin("LJY-DeviceConfigModule"); //调用android中自定义的插件名称
					const ret = DeviceConfigModule.activatorSubDev({ //login表示自定义插件的函数名，第一个表示要传递的参数
						deviceId: this.devId
					});
					// console.log(ret)
					uni.hideLoading(); //加载结束
					if (ret.code == 0) { //加载成功
						this.zishebei();
					} else { //加载失败
						uni.showToast({
							title: ret.msg,
							duration: 2000
						});
					}
				} catch (e) { //如果涂鸦智能无法连接
					uni.hideLoading(); //加载结束
					uni.showToast({
						title: '子设备添加失败',
						duration: 2000
					});
				}
			},
			zishebei() {
				try {
					uni.showLoading({
						title: '正在加载设备列表'
					});
					const deviceManageModule = uni.requireNativePlugin("LJY-DeviceManageModule"); //调用android中自定义的插件名称
					const ret = deviceManageModule.getSubDevList({ //login表示自定义插件的函数名，第一个表示要传递的参数
						deviceId: this.devId
					});
					uni.hideLoading(); //加载结束
					if (ret.code == 0) {
						// let device=JSON.parse(ret.data); 
						this.device = ret.data;
						// console.log(this.device)
					} else { //加载失败
						uni.showToast({
							title: ret.msg,
							duration: 2000
						});
					}
				} catch (e) { //如果涂鸦智能无法连接
					uni.hideLoading(); //加载结束
					uni.showToast({
						title: '设备列表加载失败,请稍后再试',
						duration: 2000
					});
				}
			},
			// del(device) {
			// 	uni.navigateTo({
			// 		url: '/pages/house/equipment/eqdel?deviceId=' + device.devId + '&name=' + device.name
			// 	});
			// },
			details(device) {
				// console.log(device.devId)
				uni.showLoading({
					title: '正在跳转到涂鸦官方设备详情界面'
				});
				try {
					const module = uni.requireNativePlugin("LJY-DeviceManageModule") //调用android中自定义的插件名称
					//跳转到涂鸦设备详情
					module.goPanelWithDeviceDetail({ //login表示自定义插件的函数名，第一个表示要传递的参数
						deviceId: device.devId
					});
					uni.hideLoading(); //加载结束
				} catch (e) { //如果涂鸦智能无法连接
					uni.hideLoading(); //加载结束
				}

			}
		}
	}
</script>

<style lang="less">
	.list {
		width: 100%;
		height: 120rpx;
		/* background-color: #4CD964; */
		border-bottom: 2rpx solid #ebebeb;
		background-color: #FFFFFF;
		align-items: center;
		display: flex;

	}

	.list_text {
		// background-color: #007AFF;
		width: 550rpx;
		margin-top: 10rpx;
	}

	.list_text2 {
		margin-top: 10rpx;
	}

	.list_text text {
		margin-left: 30rpx;
		font-size: 35rpx;
		margin-top: 5rpx;
	}

	.list_text2 text {
		margin-left: 40rpx;
		font-size: 35rpx;
		margin-top: 20rpx;
	}

	.cus-mian-four {
		width: 5%;
		margin-left: 40rpx;
	}

	.cus-mian-four text {
		float: right;
		color: #020202;
		font-size: 60rpx;
		margin-top: 7rpx;
	}

	.tianjia {
		// background: #007AFF;
		width: 100%;
		height: 150rpx;
		display: flex;
		align-items: center;
		border-bottom: 2rpx solid #ebebeb;
		background-color: #FFFFFF;
		color: #555500;
		justify-content: center;
		position: fixed;
		// position: absolute;
		// position: relative;
		top: 90%;
		z-index: 99999;
		// float: inherit;

		view {
			font-size: 40rpx;

			image {
				width: 70rpx;
				height: 50rpx;
			}
		}
	}
</style>
